package com.imooc.controller;

import com.imooc.base.BaseInfoProperties;
import com.imooc.entity.mo.MessageMO;
import com.imooc.grace.result.GraceJSONResult;
import com.imooc.service.MsgService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/msg")
@Slf4j
public class MsgController extends BaseInfoProperties {
    @Autowired
    private MsgService msgService;
    @GetMapping("list")
    public GraceJSONResult list(@RequestParam("userId") String userId,
                                @RequestParam("page") Integer page,
                                @RequestParam("pageSize") Integer pageSize){
        // mongodb从0分页 区别于数据库
        if (page == null){
            page = COMMON_START_MONGO_PAGE;
        }
        if (pageSize == null){
            pageSize = COMMON_PAGE_SIZE;
        }
        List<MessageMO> messageMOS = msgService.queryList(userId, page, pageSize);
        return GraceJSONResult.ok(messageMOS);
    }
}
